package com.example.studentportrait.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.studentportrait.domain.entity.Email;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmailMapper extends BaseMapper<Email> {
    @Insert("insert into email(content,send_account,recevice_account,title,type,status,send_time) values(" +
            "#{content},#{sendAccount},#{receiveAccount},#{title},#{type},#{status},#{sendTime} )")
    int insertEmail(Email entity);
    @Update("update email set content =#{content},send_account=#{sendAccount},recevice_account=#{receiveAccount}" +
            ",title=#{title},type=#{type},status=#{status},send_time=#{sendTime} where id=#{id} AND status=0")
    int upDateById(Email email);
    @Update("update email set status=#{status} where id=#{id}")
    int updateByEmailId(Email email);
    @Override
    int deleteById(Email entity);
    @Select("select * from email where send_account =#{account} and status=0")
    List<Email> selectByDraft(String account);
    @Select("select * from email where send_account =#{account} and status=1")
    List<Email> selectBySender(String account);
    @Select("select * from email where receive_account =#{account} and status=2 or status=3")
    List<Email> selectByReceiver(String account);
    @Select("select * from email where receive_account =#{account} and is_Collect=1")
    List<Email> selectByCollect(String account);
}
